package net.xxcxcxcx.xc_enhancedmob.render.boss_bar.unit.type.reality;

import net.minecraft.nbt.NbtCompound;
import net.xxcxcxcx.xc_enhancedmob.render.TextureElement;

import java.util.concurrent.CopyOnWriteArrayList;

import static net.xxcxcxcx.xc_enhancedmob.render.boss_bar.unit.type.BossBarTypeHelper.AllBossBarReality;

/**
 * 血条的基本类
 * <p>注意血条每层的大小一定是一样的，但是血条和血条背景大小可以随意，记得正确设置偏移量
 */
public abstract class BaseBossBarRealityType implements BossBarRealityType {
    /**
     * (x0,y0)代表左上角的偏移量，(x1,y1)代表右下角的偏移量
     */
    private int meterOffsetX0;
    private int meterOffsetX1;
    private int meterOffsetY0;
    private int meterOffsetY1;
    //bossbar每层的血条纹理(最下层、倒数第二层、倒数第三层……直到不够用时循环使用纹理)
    private CopyOnWriteArrayList<TextureElement> layers = new CopyOnWriteArrayList<>();
    private TextureElement background;//渲染的血条的背景纹理
    private TextureElement icon;
    private boolean hasIcon;
    //构造函数，用于初始化
    public BaseBossBarRealityType() {
    }

    //反序列化构造函数，用于从网络包构建
    public BaseBossBarRealityType(NbtCompound nbtCompound) {
        readCustomDataFromNbt(nbtCompound);
    }

    public int getId() {
        for (int i = 0; i < AllBossBarReality.size(); i++) {
            if (AllBossBarReality.get(i) == this.getClass()) {
                return i;
            }
        }
        return -1;
    }

    @Override
    public void writeCustomDataToNbt(NbtCompound nbt) {
    }

    @Override
    public void readCustomDataFromNbt(NbtCompound nbt) {
    }

    public TextureElement getLayer(int num) {
        return getLayers().get(num % getLayers().size());
    }

    @Override
    public CopyOnWriteArrayList<TextureElement> getLayers() {
        return layers;
    }

    @Override
    public void setLayers(CopyOnWriteArrayList<TextureElement> layers) {
        this.layers = layers;
    }

    @Override
    public TextureElement getBackground() {
        return background;
    }

    @Override
    public void setBackground(TextureElement background) {
        this.background = background;
    }

    @Override
    public int getMeterOffsetX0() {
        return meterOffsetX0;
    }

    @Override
    public void setMeterOffsetX0(int meterOffsetX0) {
        this.meterOffsetX0 = meterOffsetX0;
    }

    @Override
    public int getMeterOffsetX1() {
        return meterOffsetX1;
    }

    @Override
    public void setMeterOffsetX1(int meterOffsetX1) {
        this.meterOffsetX1 = meterOffsetX1;
    }

    @Override
    public int getMeterOffsetY0() {
        return meterOffsetY0;
    }

    @Override
    public void setMeterOffsetY0(int meterOffsetY0) {
        this.meterOffsetY0 = meterOffsetY0;
    }

    @Override
    public int getMeterOffsetY1() {
        return meterOffsetY1;
    }

    @Override
    public void setMeterOffsetY1(int meterOffsetY1) {
        this.meterOffsetY1 = meterOffsetY1;
    }

    @Override
    public TextureElement getIcon() {
        return icon;
    }

    @Override
    public void setIcon(TextureElement icon) {
        this.icon = icon;
    }

    @Override
    public void setHasIcon(boolean hasIcon) {
        this.hasIcon = hasIcon;
    }
    @Override
    public boolean hasIcon() {
        return hasIcon;
    }
}
